home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Atari Mega Archive 1
/
Atari Mega Archive - Volume 1.iso
/
telecomm
/
zmdm_src.arc
/
SZ.C
< prev
next >
Wrap
C/C++ Source or Header
|
1988-06-26
|
30KB
|
1,548 lines
/*
* ACKNOWLEDGEMENTS
*
* ZMDM was derived from rz/sz for Unix posted by
* Chuck Forsberg (...!tektronix!reed!omen!caf ). We
* thank him for his excellent code, and for giving
* us permission to use and distribute his code and
* documentation.
*
* Atari St version by:
* Jwahar Bammi
* usenet: mandrill!bammi@{decvax,sun}.UUCP
* csnet: bammi@mandrill.ces.CWRU.edu
* arpa: bammi@mandrill.ces.CWRU.edu
* CompuServe: 71515,155
*/
#include "config.h"
#define SVERSION "sz 1.23 01-15-87"
#define SSTVERSION "sz 1.01 03-07-87"
#define OS "Unix V7/BSD"
#ifndef STANDALONE
#define RETURN return
#else
int bibi() {} /* dummy */
#endif
/* #define SDEBUG */
/*
* sz.c By Chuck Forsberg
*
* cc -O sz.c -o sz USG (SYS III/V) Unix
* cc -O -DV7 sz.c -o sz Unix Version 7, 2.8 - 4.3 BSD
*
* define CRCTABLE to use table driven CRC
*
* ******* Some systems (Venix, Coherent, Regulus) do not *******
* ******* support tty raw mode read(2) identically to *******
* ******* Unix. ONEREAD must be defined to force one *******
* ******* character reads for these systems. *******
*
* A program for Unix to send files and commands to computers running
* Professional-YAM, PowerCom, YAM, IMP, or programs supporting Y/XMODEM.
*
* Sz uses buffered I/O to greatly reduce CPU time compared to UMODEM.
*
* USG UNIX (3.0) ioctl conventions courtesy Jeff Martin
*
* St v 1.01
* added support for 32 bit CRC's (Zmodem) ++jrb
*
*/
#include "zmdm.h"
#include "common.h"
#include "zmodem.h"
#ifndef Vsync /* Atari forgot these in osbind.h */
#define Vsync() xbios(37)
#endif
#ifndef Supexec
/* Some versions of osbind don't define Supexec */
#define Supexec(X) xbios(38,X)
#endif
#define SLOGFILE "szlog"
#define purgeline() while(Bconstat(1)) Bconin(1)
#define S_IFDIR 0x0010
/*
* Attention string to be executed by receiver to interrupt streaming data
* when an error is detected. A pause (0336) may be needed before the
* ^C (03) or after it.
*/
#ifdef READCHECK
char Myattn[] = { 0 };
#else
#ifdef USG
char Myattn[] = { 03, 0336, 0 };
#else
char Myattn[] = { 0 };
#endif
#endif
#if (MWC || MANX)
FILE *fopen();
#else
FILE *fopen(), *fopenb();
#endif
static unsigned long SaveIntr;
static int Resuming, ForceBin;
static int in;
/* called by signal interrupt or terminate to clean things up */
bibis(n)
int n;
{
canit(); flush_modem(); mode(0);
fprintf(STDERR, "\r\nsz: caught signal %d; exiting\n", n);
aexit(128+n);
}
/* Called when Zmodem gets an interrupt (^X) */
#ifdef ONINTR
onintr()
{
siggi = 0;
longjmp(intrjmp, -1);
}
#endif
#define ZKER
int Zctlesc; /* Encode control characters */
#ifdef STANDALONE
int main(argc, argv)
#else
int dosz(argc, argv)
#endif
int argc;
char **argv;
{
register char *cp;
register int npats;
int agcnt; char **agcv;
char **patts;
#ifdef STANDALONE
#ifdef MWC
extern char *lmalloc();
#endif
/* Set up Dta */
Fsetdta(&statbuf);
/* Get screen rez */
rez = Getrez();
drv_map = Drvmap();
#if (MWC || MANX)
#ifndef DYNABUF
#ifdef MWC
if((bufr = (unsigned char *)lmalloc((unsigned long)BBUFSIZ))
== (unsigned char *)NULL)
#else
if((bufr = (unsigned char *)Malloc((unsigned long)BBUFSIZ))
== (unsigned char *)NULL)
#endif
#else
if((bufr = dalloc()) == (unsigned char *)NULL)
#endif /* DYNABUF */
{
#ifdef REMOTE
Bauxws("Sorry, could not allocate enough memory\r\n");
#else
Bconws("Sorry, could not allocate enough memory\r\n");
#endif
Pterm(4);
}
#else /* MWC || MANX */
#ifdef DYNABUF
if((bufr = dalloc()) == (unsigned char *)NULL)
{
#ifdef REMOTE
Bauxws("Sorry, could not allocate enough memory\r\n");
#else
Bconws("Sorry, could not allocate enough memory\r\n");
#endif
Pterm(5);
}
#endif /* DYNABUF */
#endif /* MWC || MANX */
#ifndef REMOTE
STDERR = stderr;
#else
#ifndef DLIBS
if((STDERR = fopen("aux:", "rw")) == (FILE *)NULL)
{
Bauxws("Could not Open Aux Stream for Stderr\r\n");
finish();
}
setbuf(STDERR, (char *)NULL);
#else
STDERR = stdaux;
#endif /* DLIBS */
#endif /* REMOTE */
{
int speed;
speed = getbaud();
Baudrate = BAUD_RATE(speed);
SetIoBuf();
Rsconf(speed, 0,-1,-1,-1,-1);
Vsync(); Vsync();
}
#endif /* STANDALONE */
SendType = 1;
Rxtimeout = 600;
npats=0;
if (argc<2)
{
susage();
RETURN(1);
}
initz();
#ifndef STANDALONE
schkinvok(argv[0]);
#else
Progname = "sz";
#endif
SaveIntr = Setexc(0x0102, -1L);
BusErr = Setexc(2, -1L);
AddrErr = Setexc(3, -1L);
Verbose = 0;
Resuming = FALSE;
ForceBin = FALSE;
in = (-1);
vdebug = 0;
#ifdef SDEBUG
logf = (FILE *)NULL;
#endif
while (--argc) {
cp = *++argv;
if (*cp++ == '-' && *cp) {
while ( *cp) {
switch(*cp++) {
case '+':
Lzmanag = ZMAPND; break;
#ifdef CSTOPB
case '2':
Twostop = TRUE; break;
#endif
case '7':
Wcsmask=0177; break;
/*
On the St we look up the ext and decide. For Xmodem
transfers, the file is always sent in binary mode
and it is the responsibility of the receiver to
strip CR if so desired.
case 'a':
Lzconv = ZCNL;
Ascii = TRUE; break;
case 'b':
Lzconv = ZCBIN; break;
*/
/* ST extention, force binary, useful to back up every thing
* in image mode, see -B option of rz too +jrb
*/
case 'B':
ForceBin = TRUE;
Lzconv = ZCBIN;
break;
case 'C':
if (--argc < 1) {
susage();
RETURN(1);
}
Cmdtries = atoi(*++argv);
break;
case 'i':
Cmdack1 = ZCACK1;
/* **** FALL THROUGH TO **** */
case 'c':
if (--argc != 1) {
susage();
RETURN(1);
}
Command = TRUE;
Cmdstr = *++argv;
break;
case 'd':
++Dottoslash;
/* **** FALL THROUGH TO **** */
case 'f':
Fullname=TRUE; break;
case 'E':
Zctlesc = (-1); break;
case 'e':
Zctlesc = 1; break;
case 'k':
Blklen=KSIZE; break;
case 'L':
if (--argc < 1) {
susage();
RETURN(1);
}
blkopt = atoi(*++argv);
if (blkopt<32 || blkopt>1024)
{
susage();
RETURN(1);
}
break;
case 'l':
if (--argc < 1) {
susage();
RETURN(1);
}
Tframlen = atoi(*++argv);
if (Tframlen<32 || Tframlen>1024)
{
susage();
RETURN(1);
}
break;
case 'N':
Lzmanag = ZMDIFF; break;
case 'n':
Lzmanag = ZMNEW; break;
case 'o':
Wantfcs32 = FALSE; break;
case 'p':
Lzmanag = ZMPROT; break;
case 'r':
Lzconv = ZCRESUM; Resuming = TRUE; break;
case 'q':
Quiet=TRUE; Verbose=0; break;
case 't':
if (--argc < 1) {
susage();
RETURN(1);
}
Rxtimeout = atoi(*++argv);
if (Rxtimeout<10 || Rxtimeout>1000)
{
susage();
RETURN(1);
}
break;
#ifdef TESTATTN
case 'T':
Testattn = TRUE; break;
#endif
case 'u':
++Unlinkafter; break;
case 'v':
++Verbose; break;
case 'X':
++Modem; break;
case 'y':
Lzmanag = ZMCLOB; break;
default:
susage();
RETURN(1);
}
}
}
else if ( !npats && argc>0) {
if (argv[0][0]) {
npats=argc;
patts=argv;
}
}
}
if (npats < 1 && !Command)
{
susage();
RETURN(1);
}
#ifdef SDEBUG
if (Verbose > 2)
{
if ((logf = fopen(SLOGFILE, "a"))== (FILE *)NULL)
{
fprintf(STDERR, "Can't open log file %s\n",SLOGFILE);
RETURN(0200);
}
fprintf(logf, "Progname=%s\n", Progname);
vdebug = 1;
fflush(logf);
}
#endif
if ( !Quiet)
{
if (Verbose < 2)
Verbose = 2;
}
Setexc(0x0102, bibis);
Setexc(2, buserr);
Setexc(3, addrerr);
if(setjmp(busjmp))
{
/* On a bus error - instead of 2 bombs */
fprintf(STDERR,"\r\nFATAL: Bus Error\n\n");
#ifdef SDEBUG
if(logf != (FILE *)NULL)
fclose(logf);
#endif
if(in != -1)
{
stfclose(in);
in = (-1);
}
canit();
Setexc(2, BusErr);
Setexc(3, AddrErr);
Setexc(0x0102, SaveIntr);
RETURN(2);
}
if(setjmp(addrjmp))
{
/* On address error - instead of 3 bombs */
fprintf(STDERR,"\r\nFATAL: Address Error\n\n");
#ifdef SDEBUG
if(logf != (FILE *)NULL)
fclose(logf);
#endif
if(in != -1)
{
stfclose(in);
in = (-1);
}
canit();
S